package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    //修改店铺状态
    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable Integer status) {

        System.out.println(status);
        //日志
        log.info("修改店铺状态：{}", status == 1 ? "营业中" : "打烊中");
        //将status保存到redis中
        redisTemplate.opsForValue().set("SHOP_STATUS", status);
        System.out.println("查看保存后的redis中的数据：" + redisTemplate.opsForValue().get("SHOP_STATUS"));
        return Result.success();
    }

    //查询店铺状态
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        //从redis中获取店铺状态
        Integer status = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        return Result.success(status);

    }
}